package com.example.demo.controller;

import com.example.demo.mapper.UserInfoMapper;
import com.example.demo.pojo.UserInfo;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@CrossOrigin
@RestController
public class UserInfoController {
    @Autowired
    UserInfoMapper userInfoMapper;

    @GetMapping("/userinfo/{uid}")
    public UserInfo getUserInfo(@PathVariable("uid") Integer uid) {
        UserInfo userInfoById = userInfoMapper.getUserInfoById(uid);
        System.out.println(userInfoById);
        return userInfoById;
    }

    @GetMapping("/userinfo")
    public UserInfo insertUserInfo(UserInfo userInfo) {
        int i = userInfoMapper.insertUserInfo(userInfo);
        System.out.println(i);
        return userInfo;
    }

    @GetMapping("/userinfo/del/{uid}")
    public UserInfo deleteUserInfo(@PathVariable("uid") Integer uid) {
        UserInfo userInfoById = userInfoMapper.getUserInfoById(uid);
        int i = userInfoMapper.deleteUserinfoById(uid);
        System.out.println(i);
        return userInfoById;
    }

    @GetMapping("/userinfo/update")
    public UserInfo updateUserInfo(UserInfo userInfo){
        int i = userInfoMapper.updateUserInfo(userInfo);
        return userInfoMapper.getUserInfoById(userInfo.getUid());
    }
}
